<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/testTpl1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>TestCRUD</title>
    <!-- InstanceEndEditable -->
    <!-- InstanceBeginEditable name="head" -->

    <!-- InstanceEndEditable -->
    <link rel="stylesheet" type="text/css" href="../style/google/KitchenSink.css">
    <!-- InstanceBeginEditable name="additionalStyle" -->


    <!-- InstanceEndEditable -->

    <script type="text/javascript">
    var djConfig = {
		isDebug: true
		,debugAtAllCosts: true
	};
    </script>

    <script type="text/javascript" src="../../../trimpath/template-1.0.38.js"></script>
    <script type="text/javascript" src="../../../dojo/deploy/dojo.js"></script>
    <script type="text/javascript" src="../../dojo-lotex.js"></script>

    <!-- InstanceBeginEditable name="dojoRequire" -->
    <script type="text/javascript">
    dojo.require("rptp.app");
    dojo.require("lotex.api");

    dojo.hostenv.writeIncludes();
    </script>
    <!-- InstanceEndEditable -->
    <!-- InstanceBeginEditable name="headScript" -->
    <script type="text/javascript">
    function save() {
        lotex.api.save(
            "Datasource",
            {
                "id":"1128807c0f557272010f55c8738f0002",
                "name":dojo.byId("dsName").value
            }
        );
    }

    function get() {
        lotex.api.get(
            "Datasource",
            {
                "id":"1128807c0f557272010f55c8738f0002"
            },
            ["name"]
        );
    }


    function saveModelNotExist() {
    // FIXME "Null" 可能被java解析成关键字 null
        lotex.api.save(
            "NullModel",
            {
                "id":"1128807c0f557272010f55c8738f0002",
                "name":"ModifyByAsyncSave"
            }
        );
    }
    function saveModelNotFound() {
        lotex.api.save(
            "Datasource",
            {
                "id":"nothisid",
                "name":"ModifyByAsyncSave"
            }
        );
    }
    function saveNoId() {
        lotex.api.save(
            "Datasource",
            {
                "noid":"1128807c0f557272010f55c8738f0002",
                "name":"ModifyByAsyncSave"
            }
        );
    }

    function saveNoProp() {
        lotex.api.save(
            "Datasource",
            {
                "id":"1128807c0f557272010f55c8738f0002",
                "no":"ModifyByAsyncSave"
            }
        );
    }

    // @override
    lotex.api.defaultOnLoad = function(response){
        if(response.done) {
            alert("POST OK");
            if(response.result) alert(response.result.name);
        } else {
            if(response.message) alert(response.message);
            else alert("Response not valid JSON!");
        }
    }

    function getWithOnLoad() {
        lotex.api.get({
            args: [
                "Datasource",
                {
                    "id":"1128807c0f557272010f55c8738f0002"
                },
                ["name"]
            ],
            load: function(response) {
                if(response.done) {
                    if(response.result) alert(response.result.name);
                } else {
                    if(response.message) alert(response.message);
                    else alert("Response not valid JSON!");
                }
            }
        });
    }

    function getDatasetForm() {
        lotex.api.form(
            [
                "Dataset",
                {
                    "id":"1128807c0f557272010f55c8738f0002"
                },
                ["name"]
            ],
            function(response) {
                if(response.done) {
                    if(response.result) alert(response.result.name);
                } else {
                    if(response.message) alert(response.message);
                    else alert("Response not valid JSON!");
                }
            }
        );
    }

    function saveNewDatasource() {
        lotex.api.save(
            [
                "Datasource",
                lotex.encodeForm(dojo.byId("datasource"))
            ],
            function(response) {
                if(response.done) {
                    if(response.id) alert(response.id);
                } else {
                    if(response.message) alert(response.message);
                    else alert("Response not valid JSON!");
                }
            }
        );
    }
    </script>
    <!-- InstanceEndEditable -->
</head>
<body>
    <table style="width: 100%" cellspacing="0" cellpadding="0">
        <tbody>
            <tr>
                <td style="vertical-align: top" align="left">
                    <div class="ks-Info">
                        Testpage</div>
                </td>
            </tr>
            <tr>
                <td style="vertical-align: top" align="left">
                    <table class="ks-Sink" cellspacing="0" cellpadding="0">
                        <tbody>
                            <tr>
                                <td style="vertical-align: top; width: 100%; height: 100%" align="left">
                                    <div id="container">
                                        <!-- InstanceBeginEditable name="htmlContainer" -->
                                        <fieldset>
                                            <legend>save test</legend>

                                            <label>Datasource Name
                                            <input type="text" id="dsName" name="dsName" />
                                            </label>
                                            <input type="button" name="Button" value="Save" onclick="save();" />
                                        </fieldset>

                                        <fieldset>
                                            <legend>save error message test (Only run at online mode)</legend>
                                        <input type="button" name="Button" value="saveModelNotExist" onclick="saveModelNotExist();" />
                                        <input type="button" name="Button" value="saveNoId" onclick="saveNoId();" />
                                        <input type="button" name="Button" value="saveNoProp" onclick="saveNoProp();" />
                                        <input type="button" name="Button" value="saveModelNotFound" onclick="saveModelNotFound();" />
                                        </fieldset>

                                        <fieldset>
                                            <legend>get test</legend>
                                        <input type="button" name="Button" value="Get" onclick="get();" />
                                        </fieldset>

                                        <fieldset>
                                            <legend>get test(Only run at online mode)</legend>
                                        <input type="button" name="Button" value="GetWithOnload" onclick="getWithOnLoad();" />
                                        </fieldset>

                                        <fieldset>
                                            <legend>Create New Datasource</legend>
                                        <input type="button" name="Button" value="saveNewDatasource" onclick="saveNewDatasource();" />
                                        </fieldset>
                                    <!-- InstanceEndEditable -->
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    <fieldset>
        <legend>Output</legend>
        <div id="debug.output">
        </div>
    </fieldset>
</body>
<!-- InstanceEnd --></html>
